package cc.rengu.igas.bomp.core.service.trans;

import cc.rengu.igas.bomp.common.dao.MchntBaseInfoMapper;
import cc.rengu.igas.bomp.common.dao.impl.MchntBaseInfoMapperImpl;
import cc.rengu.igas.bomp.common.entity.MchntBaseInfo;
import cc.rengu.igas.bomp.common.enums.RespCodeEnum;
import cc.rengu.igas.bomp.core.service.base.ManageService;
import cc.rengu.igas.bomp.facade.bean.MchntBaseInfoBean;
import cc.rengu.igas.bomp.facade.request.MchntBaseInfoQueryRequest;
import cc.rengu.igas.bomp.facade.response.MchntBaseQueryResponse;
import cc.rengu.oltp.service.common.constant.AppParamConstant;
import cc.rengu.oltp.service.model.BizResponse;
import cc.rengu.oltp.utility.util.BeanUtil;
import cc.rengu.oltp.utility.util.ConvertUtil;
import cc.rengu.oltp.utility.util.StringUtil;
import org.springframework.util.ObjectUtils;

public class MchntBaseInfoQuery2Service extends ManageService {

    @Override
    protected Object bizBeforeCust() throws Exception {
        MchntBaseInfoQueryRequest mchntBaseInfoQueryRequest = new MchntBaseInfoQueryRequest();
        ConvertUtil.convertOutput(mchntBaseInfoQueryRequest);
        return mchntBaseInfoQueryRequest;
    }

    @Override
    protected BizResponse bizProcessCust(Object request) throws Exception {
        MchntBaseInfoQueryRequest mchntBaseInfoQueryRequest = (MchntBaseInfoQueryRequest) request;
        MchntBaseInfoMapper mchntBaseInfoMapper = new MchntBaseInfoMapperImpl();
        BizResponse bizResponse = new BizResponse();
        MchntBaseQueryResponse response = new MchntBaseQueryResponse();
        bizResponse.setRspSysId(AppParamConstant.SYS_ID);
        String instId = mchntBaseInfoQueryRequest.getHeader().getInstId();
        String mchntNo = mchntBaseInfoQueryRequest.getMchntNo();
        MchntBaseInfo mchntBaseInfo = null;
        if (StringUtil.isEmptyOrNull(instId) && StringUtil.isEmptyOrNull(mchntNo)) {
            rglog.error("必传参数instId法人号或mchntNo商户号为空！", instId, mchntNo);
            bizResponse.setRespCode(RespCodeEnum.PARAM_ERROR.getRespCode());
            bizResponse.setRespDesc(RespCodeEnum.PARAM_ERROR.getRespDesc());
            bizResponse.setResult(response);
            return bizResponse;
        }
/**
 * 根据请求参数决定响应类型，这里是判断是否根据商户号查询
 *
 * */

        mchntBaseInfo = mchntBaseInfoMapper.selectMchntBaseInfoByPrimaryKey(instId, mchntNo);
        if (ObjectUtils.isEmpty(mchntBaseInfo)) {
            rglog.error("根据条件查询商户基本信息为空");
            bizResponse.setResult(response);
            bizResponse.setRespCode(RespCodeEnum.QUERY_DATA_IS_NULL.getRespCode());
            bizResponse.setRespDesc(RespCodeEnum.QUERY_DATA_IS_NULL.getRespDesc());
            return bizResponse;
        }
        MchntBaseInfoBean mchntBaseInfoBean = new MchntBaseInfoBean();
        BeanUtil.beanCopy(mchntBaseInfo, mchntBaseInfoBean);
        response.setMchntBaseInfo(mchntBaseInfoBean);
        response.setHeader(mchntBaseInfoQueryRequest.getHeader());
        bizResponse.setResult(response);
        bizResponse.setRespCode(RespCodeEnum.TRANS_SUCCESS.getRespCode());
        bizResponse.setRespDesc(RespCodeEnum.TRANS_SUCCESS.getRespDesc());
        return bizResponse;
    }

    @Override
    protected void bizAfterCust(Object response) throws Exception {
        BizResponse bizResponse = (BizResponse) response;
        MchntBaseQueryResponse mchntBaseQueryResponse = (MchntBaseQueryResponse) bizResponse.getResult();
        ConvertUtil.convertInput(mchntBaseQueryResponse);
    }


//    /**
//     * 根据请求参数决定响应类型，这里是判断是否查询商户列表
//     *
//     * */
//    List<MchntBaseInfo> list = mchntBaseInfoMapper.selectMchntBaseInfoList();
//
//        if (!CollectionUtils.isEmpty(list)) {
//        List<MchntBaseInfoBean> baseInfoBeans = new ArrayList<>();
//        for (MchntBaseInfo mchntBaseInfo : list) {
//            MchntBaseInfoBean mchntBaseInfoBean = new MchntBaseInfoBean();
//            BeanUtil.beanCopy(mchntBaseInfo, mchntBaseInfoBean);
//            baseInfoBeans.add(mchntBaseInfoBean);
//        }
//        response.setMchntBaseInfoBeans(baseInfoBeans);
//        bizResponse.setResult(response);
//        bizResponse.setRspSysId(AppParamConstant.SYS_ID);
//        bizResponse.setRespCode(RespCodeEnum.TRANS_SUCCESS.getRespCode());
//        bizResponse.setRespDesc(RespCodeEnum.TRANS_SUCCESS.getRespDesc());
//        return bizResponse;
//    }

}